
** Table for descriptive statistics on official characteristics
	
	use "$root/output/analysis_finaldataset_withtitles.dta", clear
		
*=========================================================================	
***						Declare survey dataset
*=========================================================================	

	**declare to be a survey data set & that units are _n
		svyset _n
		
*========================================================================
*						GENERATE CATEGORIES FOR TABLES
*========================================================================		

	gen 	groups=1 if regioncode==2
	replace groups=2 if regioncode==1
	replace groups=3 if regioncode==3
	replace groups=4 if regioncode==4
	
	label define groups 1 "Asia" 2 "Anglo-" 3 "Franco-" 4 "Others"
	label val groups groups
		 
	gen moe=1 if agencyid==7
	replace moe=0 if moe==. & agencyid!=.
		
	label define agency 1 "Ministry of Education" 0 "Others"
	label val moe agency
	
	gen 	director=1 if titlecode==4
	replace director=0 if director==. & titlecode!=.
	
	gen 	deputy_assistant=1 if titlecode==3
	replace deputy_assistant=0 if deputy_assistant==. & titlecode!=.
	
	gen 	officer=1 if titlecode==7
	replace officer=0 if officer==. & titlecode!=.
		
// TABLE 1: descriptive statistics

	gen Total=100
	label var Total "\hspace{2mm} Total"
	 
	*1B: AGENCIES by sample + region ---------------------------------------
	eststo clear
	preserve
		replace agencyid=13 if agencyid==.
		tabulate agencyid, gen(agency_)
		
		gen agency_14=0
		
		forval n=2/4{
		replace agency_14=1 if agency_`n'==1
		drop agency_`n'
		}
		
		forval n=8/10{
		replace agency_14=1 if agency_`n'==1
		drop agency_`n'
		}
		
		label var agency_13 "Missing"

		
		foreach var of varlist agency_* {
			replace `var'=`var'*100	
			}

		local var agency_
		label variable `var'5 "Higher Education Ministry/Agency"
		label variable `var'6 "Local Government"	
		label variable `var'1 "Centre of Government"
		label variable `var'7 "\textbf{Agency} (\% of respondents) & & & & & \\\hline Ministry of Education"
		label variable `var'11 "TVET/Skills Ministry/Agency"
		label variable `var'12 "University"
		label variable `var'14 "Others"
		label variable `var'13 "Missing"

		eststo: svy: mean agency_7 agency_11 agency_5 agency_1 agency_12 agency_6 agency_14 agency_13 Total
		eststo: svy: mean agency_7 agency_11 agency_5 agency_1 agency_12 agency_6 agency_14 agency_13 Total if groups==1
		eststo: svy: mean agency_7 agency_11 agency_5 agency_1 agency_12 agency_6 agency_14 agency_13 Total if groups==2
		eststo: svy: mean agency_7 agency_11 agency_5 agency_1 agency_12 agency_6 agency_14 agency_13 Total if groups==3
		eststo: svy: mean agency_7 agency_11 agency_5 agency_1 agency_12 agency_6 agency_14 agency_13 Total if groups==4
		
		estout , l 
		
		esttab using tables/descriptive_agency.tex, replace f ///
		nostar noobs nonumbers mtitle("" "" "Africa" "Africa" "") mgroups("Sample" "Pacific" "phone" "phone" "", pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		l b("%12.1f") nobaselevels noparentheses nonotes not
	restore	

	*1c: JOB TITLE by sample + region --------------------------------------
	eststo clear
	preserve
		tabulate titlecode, gen(agency_)

		foreach var of varlist agency_* {
			replace `var'=`var'*100	
			}

		local var agency_
		label variable `var'1 "Academic"
		label variable `var'2 "Advisor"
		label variable `var'3 "Assistant/Deputy Director"
		label variable `var'4 "Director"
		label variable `var'5 "\textbf{Job Title} (\% of respondents)  & & & & & \\ \hline Minister"
		label variable `var'6 "Missing"	
		label variable `var'7 "Officer"	
		label variable `var'8 "Permanent Secretary/Director General"

		eststo: svy: mean agency_5 agency_2  agency_8  agency_4  agency_3  agency_7  agency_1  agency_6 Total
		eststo: svy: mean agency_5 agency_2  agency_8  agency_4  agency_3  agency_7  agency_1 agency_6 Total if groups==1
		eststo: svy: mean agency_5 agency_2  agency_8  agency_4  agency_3  agency_7  agency_1  agency_6 Total if groups==2
		eststo: svy: mean agency_5 agency_2  agency_8  agency_4  agency_3  agency_7  agency_1  agency_6 Total if groups==3
		eststo: svy: mean agency_5 agency_2  agency_8  agency_4  agency_3  agency_7  agency_1 agency_6 Total if groups==4
		
		esttab using tables/descriptive_agency.tex, append f ///
		nostar noobs nonumbers nomtitle booktabs ///
		l b("%12.1f") nobaselevels noparentheses nonotes not	
	restore	

	*1D: Gender by sample + region --------------------------------------
	eststo clear
	preserve
		gen gender=1 if male==0
		replace gender=2 if male==1
		replace gender=3 if male==.
		
		tabulate gender, gen(agency_)

		foreach var of varlist agency_* {
			replace `var'=`var'*100	
			}
		local var agency_
		label variable `var'1 "\textbf{Gender} (\% of respondents) & & & & & \\ \hline  Female"
		label variable `var'2 "Male"
		label variable `var'3 "Missing"
		
		eststo: svy: mean agency_? Total
		eststo: svy: mean agency_? Total if groups==1
		eststo: svy: mean agency_? Total if groups==2
		eststo: svy: mean agency_? Total if groups==3
		eststo: svy: mean agency_? Total if groups==4
		
		esttab using tables/descriptive_agency.tex, append f ///
		nostar noobs nonumbers nomtitle booktabs ///
		l b("%12.1f") nobaselevels noparentheses nonotes not	
	restore	

	*1A: REGIONS
	eststo clear
	preserve
		tabulate groups, gen(region_)
		foreach var of varlist region_* {
		replace `var'=`var'*100	
		}

			local var region_
		label variable `var'1 "\hline Region (\% of respondents) & & & & & \\ \hline Asia  "
		label variable `var'2 "Anglophone"
		label variable `var'3 "Francophone"
		label variable `var'4 "Others"

		eststo: svy: mean region_* Total
		esttab , extracols(4) nostar noobs nonumbers ///
		l b("%12.2f") ///
		mgroups("Full" "Asia" "Anglophone" "Francophone"  "Others") ///
		mtitle("Sample" "" "Africa" "Africa" "")
		
		est store a
		
		esttab using tables/descriptive_region.tex, replace f ///
		nostar nonumbers nomtitle booktabs ///
		l b("%12.1f") nobaselevels noparentheses nonotes not
	restore
	
